﻿using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Tsanie.ShellExt.Definitions;

namespace Tsanie.ShellExt
{
    [Guid("B0D9EBC0-5612-4359-B91B-BECA3365CA45")]
    [ComVisible(true)]
    public class ManagerThumbnail : ThumbnailHandlerBase
    {
        #region - ThumbnailHandlerBase 成员 -

        protected override Bitmap GetImage
        {
            get
            {
                if (this.Ext != null)
                {
                    ThumbnailBaseProvider provider = Manager.GetThumbnailProvider(this.Ext);
                    if (provider != null)
                    {
                        try
                        {
                            return provider.GetBitmap(
                                this.Filename,
                                this.GetFlag,
                                this.RecomendedColorDepth,
                                this.RecomendedSize
                                );
                        }
                        catch (Exception e)
                        {
                            Common.OutputDebugString("get_GetImage():: '{0}'", this.Filename);
                            Common.OutputError("get_GetImage()", e);
                        }
                    }
#if DEBUG
                    else
                    {
                        Common.OutputDebugString("get_GetImage():: Can't find the provider... {0}", this.Filename);
                    }
#endif
                }
#if DEBUG
                else
                {
                    Common.OutputDebugString("get_GetImage():: Hasn't extension... {0}", this.Filename);
                }
#endif
                return null;
            }
        }

        protected override ThumbnailFlags GetFlag
        {
            get
            {
                if (this.Ext != null)
                {
                    ThumbnailBaseProvider provider = Manager.GetThumbnailProvider(this.Ext);
                    if (provider != null)
                    {
                        try
                        {
                            return provider.Flags;
                        }
                        catch (Exception e)
                        {
                            Common.OutputDebugString("get_GetFlag():: '{0}'", this.Filename);
                            Common.OutputError("get_GetFlag()", e);
                        }
                    }
                }
                return base.GetFlag;
            }
        }

        #endregion
    }
}
